{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "1e46eb2e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Support CUDA ?:  True\n",
      "tensor([1.], device='cuda:0')\n",
      "tensor([[-0.2923, -0.2662, -1.3111],\n",
      "        [-0.1540, -0.6607,  0.1045]], device='cuda:0')\n",
      "tensor([[ 0.7077,  0.7338, -0.3111],\n",
      "        [ 0.8460,  0.3393,  1.1045]], device='cuda:0')\n",
      "Support cudnn ?:  True\n"
     ]
    }
   ],
   "source": [
    "# Summary: 检测当前Pytorch和设备是否支持CUDA和cudnn\n",
    "import torch\n",
    "from torch.backends import cudnn\n",
    "\n",
    "print(\"Support CUDA ?: \", torch.cuda.is_available())\n",
    "x = torch.Tensor([1.0])\n",
    "xx = x.cuda()\n",
    "print(xx)\n",
    "y = torch.randn(2, 3)\n",
    "yy = y.cuda()\n",
    "print(yy)\n",
    "zz = xx + yy\n",
    "print(zz)\n",
    "# CUDNN TEST\n",
    "print(\"Support cudnn ?: \", cudnn.is_acceptable(xx))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "17ded3ae-2ec9-4a29-877b-af1fdb8a16e4",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.19"
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
